<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Promise</title>
</head>

<body>
  <script>
    const imgAddress = 'https://q.qlogo.cn/headimg_dl?dst_uin=1003823662&spec=5';

    const imgPromise = (url) => {
      return new Promise((resolve, reject) => {
        const img = new Image();
        img.src = url;
        img.onload = () => {
          resolve(img);
        };
        img.onerror = () => {
          reject(new Error('图片有误'));
        };
      });
    };

    imgPromise(imgAddress)
      .then(img => {
        document.body.appendChild(img);
      })
      .cache(err => {
        document.body.innerHTML = err;
      });
  </script>
</body>

</html>